"""
author: yzh
date: 2021/1/19
"""
import requests
import re
from apps.DjangoWeb.spider.previousQuery.getVPNCookie import webvpnCookie,webvpncookieList
vpn_key_url = 'https://webvpn.ecut.edu.cn/vpn_key/update'
getkeyList = ["","",""]
def getkey(username,password):
    webvpnCookie(username,password)

    r_vpn_key_headers = {
        'User-Agent': 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19',
        "Pragma": "no-cache",
        "Accept": "application/json, text/plain, */*",
        "Cookie": webvpncookieList[0],
        "Upgrade-Insecure-Requests": "1"

    }

    r_vpn_key = requests.get(vpn_key_url, headers=r_vpn_key_headers, allow_redirects=False)

    getkeyList[0] = 'webvpn_username=' + re.findall(r'webvpn_username=(.*?);', r_vpn_key.headers['set-cookie'])[0] + '; '
    getkeyList[1] = '_webvpn_key=' + re.findall(r'_webvpn_key=(.*?);', r_vpn_key.headers['set-cookie'])[0] + '; '
    getkeyList[2] = r_vpn_key.headers['set-cookie']
    return getkeyList
